package com.gsit.expenditure.client.domina;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import com.gsit.expenditure.domain.Customer;
import com.gsit.expenditure.domain.CustomerAddress;
import com.gsit.expenditure.domain.Vehicle;
import com.gsit.expenditure.domain.Vendor;
import com.gsit.expenditure.domain.VendorAddress;

public class VendorBean implements BeanHendler<Vendor> {
	
	private StringProperty firstName = new SimpleStringProperty("");
	private StringProperty lastName = new SimpleStringProperty("");
	private StringProperty address1 = new SimpleStringProperty("");

	private StringProperty address2 = new SimpleStringProperty("");

	private StringProperty city = new SimpleStringProperty("");

	private StringProperty state = new SimpleStringProperty("");

	private StringProperty country = new SimpleStringProperty("");

	private StringProperty pincode = new SimpleStringProperty("");
	
	private StringProperty phone = new SimpleStringProperty("");
	private StringProperty mobile = new SimpleStringProperty("");
	
	
	
	private Vendor vendor;
	private Customer customer;
	
	private VendorBean(){
		if(vendor == null){
			vendor  = new Vendor();
			
		}
		this.vendor = vendor;
		init(vendor);
	}
	
	public VendorBean(Vendor vendor){
		if(vendor ==null){
			vendor = new Vendor();
			if(vendor.getAddress()==null){
				VendorAddress vendorAddress = new VendorAddress();
				vendor.setAddress(vendorAddress);
			}
		}
		this.vendor = vendor;
		init(vendor);
	}

	
	@Override
	public void init(Vendor vendor) {
		if (vendor!=null) {
			
			firstName.setValue( vendor.getFirstName());
			lastName.setValue( vendor.getLastName());
			phone.setValue(vendor.getPhone());
			mobile.setValue(vendor.getMobile());
			
			if (vendor.getAddress() !=null) {
					address1.setValue(vendor.getAddress().getAddress1());
					address2.setValue(vendor.getAddress().getAddress2());
					city.setValue(vendor.getAddress().getCity());
					state.setValue(vendor.getAddress().getState());
					country.setValue(vendor.getAddress().getCountry());
					pincode.setValue(vendor.getAddress().getPinCode());
				}
			}
		}

	@Override
	public void reLoad(Vendor vendor) {
		this.vendor = vendor;
			init(vendor);
		}

	@Override
	public void clean() {
		firstName.setValue("");
		lastName.setValue("");
		address1.setValue("");
		address2.setValue("");
		state.setValue("");
		country.setValue("");
		pincode.setValue("");
		city.setValue("");
		
		
		phone.setValue("");
		mobile.setValue("");
		
	}

	@Override
	public Vendor getObject() {
		vendor.setFirstName(firstName.getValue());
		vendor.setLastName(lastName.getValue());
		
		VendorAddress vendorAddress = new VendorAddress();
		vendorAddress.setAddress1(address1.getValue());
		vendorAddress.setAddress2(address2.getValue());
		vendorAddress.setCity(city.getValue());
		vendorAddress.setCountry(country.getValue());
		vendorAddress.setState(state.getValue());
		vendorAddress.setPinCode(pincode.getValue());
		
		vendor.setAddress(vendorAddress);
		vendor.setPhone(phone.getValue());
		vendor.setMobile(mobile.getValue());
		
		
		
		return vendor;
		
	}

	public StringProperty getFirstName() {
		return firstName;
	}

	public void setFirstName(StringProperty firstName) {
		this.firstName = firstName;
	}

	public StringProperty getLastName() {
		return lastName;
	}

	public void setLastName(StringProperty lastName) {
		this.lastName = lastName;
	}

	public StringProperty getAddress1() {
		return address1;
	}

	public void setAddress1(StringProperty address1) {
		this.address1 = address1;
	}

	public StringProperty getAddress2() {
		return address2;
	}

	public void setAddress2(StringProperty address2) {
		this.address2 = address2;
	}

	public StringProperty getCity() {
		return city;
	}

	public void setCity(StringProperty city) {
		this.city = city;
	}

	public StringProperty getState() {
		return state;
	}

	public void setState(StringProperty state) {
		this.state = state;
	}

	public StringProperty getCountry() {
		return country;
	}

	public void setCountry(StringProperty country) {
		this.country = country;
	}

	

	public StringProperty getPincode() {
		return pincode;
	}

	public void setPincode(StringProperty pincode) {
		this.pincode = pincode;
	}

	public StringProperty getPhone() {
		return phone;
	}

	public void setPhone(StringProperty phone) {
		this.phone = phone;
	}

	public StringProperty getMobile() {
		return mobile;
	}

	public void setMobile(StringProperty mobile) {
		this.mobile = mobile;
	}

	public Vendor getVendor() {
		return vendor;
	}

	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}

	@Override
	public String toString() {
		return "VendorBean [firstName=" + firstName + ", lastName=" + lastName
				+ ", address1=" + address1 + ", address2=" + address2
				+ ", city=" + city + ", state=" + state + ", country="
				+ country + ", pincode=" + pincode + ", phone=" + phone
				+ ", mobile=" + mobile + ", vendor=" + vendor + "]";
	}

	
	

}
